class Solution(object):
    def maxSatisfied(self, customers, grumpy, minutes):
        n = len(customers)
        num = sum(customers) - sum([customers[i] * grumpy[i] for i in range(n)])
        t = 0
        for i in range(minutes):
            t += customers[i] * grumpy[i]
        max_t = t
        for i in range(n - minutes):
            t += customers[i + minutes] * grumpy[i + minutes] - customers[i] * grumpy[i]
            max_t = max(t, max_t)
        return num + max_t

data = Solution()
customers = [1,0,1,2,1,1,7,5]
grumpy = [0,1,0,1,0,1,0,1]
minutes = 3
print(data.maxSatisfied(customers, grumpy, minutes))